package com.ssm.zhihu_ssm.service.impl;


import com.ssm.zhihu_ssm.dao.UserDAO;
import com.ssm.zhihu_ssm.entity.User;
import com.ssm.zhihu_ssm.entity.UserMessage;
import com.ssm.zhihu_ssm.service.UserMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service(value = "userMessageService")
public class UserMessageImpl implements UserMessageService {

    @Resource
    private UserDAO userMapper;

    @Override
    public User findUserMessage(int id) {
        User user = userMapper.findUserMessage(id);
        return user;
    }

    @Override
    public boolean setUserMessage(UserMessage userMessage) {
        User user = userMapper.findUserMessage(userMessage.getId());
        if (user==null)
        {
            userMapper.insertUserMessage(userMessage);
        }else {

            userMapper.updataUserMessage(userMessage);
        }

        return true;
    }

    @Override
    public boolean setimg(int id, String adress) {
        User user = userMapper.findUserMessage(id);
        if (user != null) {
            UserMessage userMessage = new UserMessage();
            userMessage.setId(id);
            userMessage.setImg(adress);
            userMapper.setimg(userMessage);
            return true;
        }else {
            return false;
        }


    }
}
